<?php
namespace Kuoqi;
use Kuoqi;
use Kuoqi\Error;
use ArrayObject;

/**
 * Class Model
 * @package Kuoqi
 * User kuoqi
 * Datetime 2022/2/28 22:56
 * Remark 基本上已经没用了
 */
class Model extends ArrayObject{
	
	public $isArrayObject = true;//判定类型为ArrayObject的数组
	
	public function __construct(){}
	
	//设置一个属性,将属性使用为数组的方式
	public function offsetSet($n,$v){
			
	}
	
	//获取一个属性,将属性使用为数组的方式
	public function offsetGet($n){
			
	}

    /**
     * @param $mdName
     * @param $mdType
     * @return null
     * User kuoqi
     * Datetime 2022/3/1 10:35
     * Remark 使用某个模型
     */
	static public function useModel($mdName,$mdType)
	{

		$mdType = ucwords($mdType);
		$mdName = ucwords($mdName);
		$mdModel = ucwords(\Kuoqi::$app->route->m);
        $modelc = ucwords(Config::get('PATH_COMMON'));
        $rootmodel = $modelname = Config::get('RL').'App'.Config::get('RL').$mdModel.Config::get('RL').$mdType.Config::get('RL').$mdName.$mdType;
        Error::dieOff();//忽略接下来的die异常
        if(class_exists($modelname)){
            Error::dieOn();//显示异常
            $model = new $modelname();
        }else{
            $modelname = Config::get('RL').'App'.Config::get('RL').$modelc.Config::get('RL').$mdType.Config::get('RL').$mdName.$mdType;
            if(class_exists($modelname)){
                Error::dieOn();//显示异常
                $model = new $modelname();
            }else{
                $modelname = Config::get('RL').'Kuoqi'.Config::get('RL').'Model'.Config::get('RL').$mdType;
                if(class_exists($modelname)){
                    Error::dieOn();//显示异常
                    $model = new $modelname();
                }else{
                    Error::dieOn();//显示异常
                    return new Error('Model ['.$rootmodel.'] is not exist');
                }
            }
        }

		return $model;
	}
	
	protected $errMessage;
	public function getError(){ return $this->errMessage;}
	public function setError($err){ return $this->errMessage = $err;}
}